<template>
  <div>
    <NavBar @click-left="onClickLeft" title="登录" left-arrow></NavBar>
    <Form @submit="onSubmit" class="g-mt-10">
      <Field
        v-model="phone"
        name="手机号码"
        label="手机号码"
        placeholder="手机号码"
        :rules="[{ required: true, message: '请填写手机号码' },{ pattern, message: '请填写手机号码' }]"
      />
      <Field
        v-model="password"
        name="password"
        label="登录密码"
        placeholder="登录密码"
        :rules="[{ required: true, message: '请填写登录密码' }]"
      />
      <div class="g-padding-10">
        <Button type="primary" round block native-type="submit" :loading='loading'>登录</Button>
      </div>
    </Form>
  </div>
</template>

<script>
import { Form, Field, Button, NavBar } from "vant";
export default {
  name: "App",
  components: { Form, Field, Button, NavBar },
  props: {
    redirect: {
      type: String,
      default: "/"
    }
  },
  data() {
    return {
      phone: "",
      password: "",
      loading: false,
      
    };
  },
  methods: {
    onSubmit() {
      this.loading = true;
      sessionStorage.setItem('auth',true)
      setTimeout(()=>{
        location.href = this.redirect;
      },500)
    },
    onClickLeft() {
      location.href = this.redirect
    }
  },

  created() {
    let redirect = location.href.match("redirect=(.+)");
    this.redirect = redirect ? decodeURIComponent(redirect) : '/';
  }
};
</script>

<style scoped lang='scss'>
@import '@/assets/common.scss';
</style>
